

/******************************************************************/
/*                    DoFile Replication file
	Review of Economics and Statistics
	
		Victim incentives and criminal activity: 
		Evidence from bus driver robberies in Chile   		  
			
			Author: Patricio Domínguez
			September, 2020										  */

/******************************************************************/

/* Notes: This dofile generates Figures 6 and 7 */

set scheme plotplain

global rep "/Users/patriciodominguez/RES_Dominguez Dropbox/Patricio Dominguez/Replication/TS"

use "$rep/dta/cip.dta", clear

su
g pre =0
replace pre=1 if week<42
 
g tra =0
replace tra=1 if week>=42 & week<110
 
g post =0
replace post=1 if week>=110

g period =0 if pre
replace period =1 if tra
replace period=2 if post
g post_cash = post*cash
g tra_cash = tra*cash

g year=2005 if week<52
replace year=2006 if week>=52 &week<104
replace year=2007 if week>=104 &week<156
replace year=2008 if week>=156 &week<208
replace year=2009 if week>=208 &week<260
replace year=2010 if week>=260 
g month = int((week)/52*12)+1 if year ==2005
replace month = int((week-52+1)/52*12)+1 if year ==2006
replace month = int((week-52*2)/52*12)+1 if year ==2007
replace month = int((week-52*3)/52*12)+1 if year ==2008
replace month = int((week-52*4)/52*12)+1 if year ==2009
replace month = int((week-52*5)/52*12)+1 if year ==2010
replace month=12 if month==13

** Figure 6
// plot of crimes in cash-intensive places
twoway (line crime week if sp==1 & cash==1, lc(black) xline(42 110)) ///
		(line crime week if sp==1 & cash==0, lc(gs12) lp(solid) ),  ///
		legend(label(1 "Cash") label(2 "Noncash") size(med) ) ytitle("# Incidents", size(med) ) xtitle("") ///
		tlabel(0 "2005" 52 "2006" 105 "2007" 158 "2008" 210 "2009" 262 "2010"  314 "2011", labsize(MED) nogrid) xscale(range(0 313) )
		graph export "$rep/Figures/cash_intensives_evol.pdf", replace
		

//I exclude pre-period in order to compare shocks of similar magnitudes in buses vs other cash-related places
postfile pdr b se w dd place using bwrobust, replace
foreach p in 0 1 { 
forvalues i=14/30 { 
	local w= `i'*10-1
	local week=`i'*10
	di `i' `p'
	qui reg crime i.month post if sp==`p' & week<`week' & cash==1 & pre==0, r
	post pdr (_b[post]) (_se[post])  (`w') (0) (`p')
	local w=`i'*10+1
	qui reg crime i.month post cash post_cash if sp==`p' & week<`week' & pre==0, r
	post pdr (_b[post_cash]) (_se[post_cash])  (`w') (1) (`p')
}
}
postclose pdr

preserve
use bwrobust, clear
su
gen l = b - 1.96*se 
gen u = b + 1.96*se 

* Figure 7
twoway (rcap l u w if dd==0 & p==1, lc(black) ) (scatter b w if dd==0 & p==1,  m(O) mc(black)) ///
(rcap l u w if dd==1 & p ==1, lc(gs12) ) (scatter b w if dd==1 & p ==1,  m(S) mc(gs12)) ///
(rcap l u w if dd==0 & p ==0, lc(black)  ) (scatter b w if dd==0 & p ==0,  m(T) mc(black)) ///
(rcap l u w if dd==1 & p ==0,  lc(gs12)) (scatter b w if dd==1 & p ==0,  m(D) mc(gs12)), ///
yline(0, lcolor(black) lpattern(dash)) scheme(plotplainblind) legend(order(2 "CIP-TS" 4 "CIP-DD" 6 "Bus-TS" 8 "Bus-DD" )) ///
xtitle("") ytitle(Estimated Effect) 	///	
tlabel(156 "2008" 208 "2009" 260 "2010" 314 "2011", labsize(med) nogrid) xscale(range(150 313) )
	graph export "$rep/Figures/post_week.pdf", replace
